package com.fc.test.controller.admin;

import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.github.pagehelper.PageInfo;
import com.fc.test.common.base.BaseController;
import com.fc.test.common.domain.AjaxResult;
import com.fc.test.model.auto.TAbbCommission;
import com.fc.test.model.custom.TableSplitResult;
import com.fc.test.model.custom.Tablepar;
import com.fc.test.model.custom.TitleVo;
import com.fc.test.service.TAbbCommissionService;
import io.swagger.annotations.Api;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("TAbbCommissionController")
@Api(value = "")
public class TAbbCommissionController extends BaseController{

	private String prefix = "admin/tAbbCommission";
	@Autowired
	private TAbbCommissionService tAbbCommissionService;

	//Logical.OR是指value 中的权限任选其一  Logical.AND是指value 中的权限都要有，默认为and
	@GetMapping("view/{type}")
	@RequiresPermissions(value = {"gen:tAbbCommission:view", "gen:tAbbCommission:view1"}, logical = Logical.OR)
    public String view(Model model,@PathVariable("type") String type)
    {
		String str="";
		model.addAttribute("type",type);
		setTitle(model, new TitleVo("列表", str+"管理", true,"欢迎进入"+str+"页面", true, false));
		if (type.equals("3")){
			return prefix + "/pingtailist";
		}else{
			return prefix + "/list";
		}
    }


	@PostMapping("list/{type}")
	@RequiresPermissions("gen:tAbbCommission:list")
	@ResponseBody
	public Object list(Tablepar tablepar,String searchTxt,@PathVariable("type")int type,String starttime,String endtime){
		PageInfo<Map> page=tAbbCommissionService.list(tablepar,searchTxt,type,starttime,endtime);
		TableSplitResult<Map> result=new TableSplitResult<Map>(page.getPageNum(), page.getTotal(), page.getList());
		return  result;
	}

	/**
     * 新增
     */
    @GetMapping("/add")
    public String add(ModelMap modelMap)
    {
        return prefix + "/add";
    }


	@PostMapping("add")
	@RequiresPermissions("gen:tAbbCommission:add")
	@ResponseBody
	public AjaxResult add(TAbbCommission tAbbCommission,Model model){
		int b=tAbbCommissionService.insertSelective(tAbbCommission);
		if(b>0){
			return success();
		}else{
			return error();
		}
	}

	/**
	 * 删除用户
	 * @param ids
	 * @return
	 */
	@PostMapping("remove")
	@RequiresPermissions("gen:tAbbCommission:remove")
	@ResponseBody
	public AjaxResult remove(String ids){
		int b=tAbbCommissionService.deleteByPrimaryKey(ids);
		if(b>0){
			return success();
		}else{
			return error();
		}
	}



	/**
	 * 修改跳转
	 * @param id
	 * @param mmap
	 * @return
	 */
	@GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        mmap.put("TAbbCommission", tAbbCommissionService.selectByPrimaryKey(id));

        return prefix + "/edit";
    }

	/**
     * 修改保存
     */
    @RequiresPermissions("gen:tAbbCommission:edit")
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TAbbCommission record)
    {
        return toAjax(tAbbCommissionService.updateByPrimaryKeySelective(record));
    }





}
